<?php
namespace app\index\controller;
use think\Config;
use think\Db;

class Rank extends Common
{
	//首页
    public function index()
    {
		$baseurl=Config::get("block_url");
		
		
		$page=request()->param('page');
		if(!$page | $page<1)
		{
			$page = 1;
		}
		
		$url = $baseurl . "v1/index/block/preview";
		
		$info = $this->curl_request($url);
		$cinfo = json_decode($info,true);
		$index_data = $cinfo['data'];
		
		$max_power = $index_data['miner_power'];
		
		
		//真实矿工
		$url = $baseurl . "v1/index/miner/list";
		$arr['page']=$page;
		$info = $this->curl_request($url,$arr);
		$cinfo = json_decode($info,true);
		$level_data = $cinfo['data'];
		
		$level_data = $this->u_array_sort($level_data,'QualityAdjPower','desc');
		$i=0;
		foreach($level_data AS &$v)
		{
			$i++;
			$v['i']=$i;
			$v['width'] = 0;
			if($v['QualityAdjPower']>0)
			{
				$v['width'] = round($v['QualityAdjPower']/$max_power,2) * 100;
			}
			
			$v['QualityAdjPower'] = $this->chk_power($v['QualityAdjPower']);
			
			$v['amount']=$this->sctonum($v['amount'] / 1000000000000000000);
			
			if(empty($v['area']))
			{
				$v['area'] = "N/A";
			}
			
		}
		unset($v);
		
		$page_arr=array();
		$page_arr['this']=$page;
		$page_arr['next']=$page+1;
		$page_arr['pre']=$page-1;
		//$page_arr['next_last']=10;
		$page_arr['next_last']=$page;
		
		
		$this->assign("page",$page_arr);
		
		$this->assign("level_data",$level_data);
		
		return $this->fetch();
    }
	
}
